<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.templateName" clearable placeholder="请输入模板名称" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
    <!-- <el-select v-model="query.typeid" clearable placeholder="请选择巡检类型" class="filter-item" @change="selectType">
      <el-option v-for="(item,index) in inspectionType" :key="index" :label="item.name" :value="item.value" />
    </el-select>
    <el-select v-model="query.objid" clearable placeholder="请选择巡检对象" class="filter-item" @change="toQuery">
      <el-option v-for="(itemobject,index) in inspectionObject" :key="index" :label="itemobject.label" :value="itemobject.id" />
    </el-select> -->
    <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <!-- 新增 -->
    <div style="display: inline-block;margin: 0px 2px;">
      <el-button
        v-permission="['ADMIN','INSPECTIONTEMPLATE_ALL','INSPECTIONTEMPLATE_CREATE']"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-plus"
        @click="$refs.form.dialog = true"
      >
        新增
      </el-button>
      <eForm ref="form" :is-add="true" :is-view="false" :sup-this="supThis" />
    </div>
  </div>
</template>

<script>
import eForm from './form'
import { INSPECTION_TYPES } from '@/constants/consts'
import { dictByName } from '@/api/dict'
import { byDictId } from '@/api/dictDetail'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    },
    supThis: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      inspectionType: INSPECTION_TYPES,
      inspectionObject: []
    }
  },
  methods: {
    toQuery() {
      this.$parent.page = 0
      this.$parent.init()
    },
    selectType(index) {
      let typeName = ''
      for (var i in INSPECTION_TYPES) {
        if (INSPECTION_TYPES[i].value === index) {
          typeName = INSPECTION_TYPES[i]['name']
          break
        }
      }
      this.byNameinfo(typeName)
    },
    byNameinfo(name) {
      this.inspectionObject = []
      if (name) {
        dictByName(name).then(res => {
          if (res.id !== null) {
            byDictId(res.id).then(resobject => {
              this.inspectionObject = resobject
            })
          }
        })
      }
    }
  }
}
</script>
